<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>留言管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		$(document).ready(function() {
		});
		function page(n,s){
			$("#pageNo").val(n);
			$("#pageSize").val(s);
			$("#searchForm").submit();
        	return false;
        }
		  
		
		function replyToUser(id){
			var replyContent = $('#reply_content_'+id).val();
			var params = {'id':id,'replyContent':replyContent};
			$.post('${ctx}/mom/guestBook/reply',params,function(data){
				
				if(data['success'] == 'true'){
					$('#status_'+id).html('回复未阅');
					$('#reply_'+id).html(replyContent);
					
				}
				 
			});
			
			
		}
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li class="active"><a href="${ctx}/mom/guestBook/">留言列表</a></li>
		<shiro:hasPermission name="momarketing:guestBook:edit"><li><a href="${ctx}/mom/guestBook/form">留言添加</a></li></shiro:hasPermission>
	</ul>
	<form:form id="searchForm" modelAttribute="guestBook" action="${ctx}/mom/guestBook/" method="post" class="breadcrumb form-search">
		<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
		<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
		<label>内容 ：</label><form:input path="content" htmlEscape="false" maxlength="50" class="input-medium"/>
		<label>内容 ：</label>
		<form:select path="status">
			<form:option value="0">未回复</form:option>
			<form:option value="1">回复未阅</form:option>
			<form:option value="2">回复已阅</form:option>
		</form:select>
		&nbsp;<input id="btnSubmit" class="btn btn-primary" type="submit" value="查询"/>
	</form:form>
	<tags:message content="${message}"/>
	<table id="contentTable" class="table table-striped table-bordered ">
		<thead><tr>
		<th>姓名</th>
		<th>手机</th>
		<th>留言内容</th>
		<th nowrap="nowrap">状态</th>
		<th>回复内容</th><shiro:hasPermission name="momarketing:guestBook:edit"><th>操作</th></shiro:hasPermission></tr></thead>
		<tbody>
		<c:forEach items="${page.list}" var="guestBook">
			<tr>
				<td nowrap="nowrap"><a href="${ctx}/mom/guestBook/form?id=${guestBook.id}">  <c:if test="${empty guestBook.member }">非会员</c:if>  <c:if test="${not empty guestBook.member }">${guestBook.member.name}</c:if>    </a></td>
				<td>${guestBook.member.mobile}</td>
				<td>${guestBook.content}</td>
				<td nowrap="nowrap">
					<span id="status_${guestBook.id }">
						<c:if test="${guestBook.status eq '0' }">未回复</c:if>
						<c:if test="${guestBook.status eq '1' }">回复未阅</c:if>
						<c:if test="${guestBook.status eq '2' }">回复已阅</c:if>
					</span>
				</td>
				<td><span id="reply_${guestBook.id }">${guestBook.reply}</span></td>
				<shiro:hasPermission name="momarketing:guestBook:edit"><td nowrap="nowrap">
    				<c:if test="${guestBook.status eq '0' }">
	    				<button type="button" class="btn btn-success" data-toggle="modal" data-target="#myModal_${guestBook.id }">回复</button>
    				</c:if>
    				<c:if test="${guestBook.status eq '1'}"><a class="btn btn-primary" href="${ctx}/mom/guestBook/form?id=${guestBook.id}">修改</a></c:if>
					<a href="${ctx}/mom/guestBook/delete?id=${guestBook.id}"  class="btn btn-danger"  onclick="return confirmx('确认要删除该留言吗？', this.href)">删除</a>
					<!-- 回复内容 -->
						<div id="myModal_${guestBook.id }" class="modal hide fade" tabindex="-1" style="width:300px"
									role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
									<div class="modal-header">
										<button type="button" class="close" data-dismiss="modal"
											aria-hidden="true">×</button>
										<h3 id="myModalLabel">回复留言</h3>
									</div>
									<div class="modal-body">
										<textarea name="reply" id="reply_content_${guestBook.id }" rows="5" cols="20"></textarea>
									</div>
									<div class="modal-footer">
										<button class="btn" data-dismiss="modal" aria-hidden="true">关闭</button>
										<button class="btn btn-primary"  data-dismiss="modal" aria-hidden="true" onclick="replyToUser('${guestBook.id }');">回复</button>
									</div>
						</div> <!-- 回复内容 结束-->
					
				</td>
				</shiro:hasPermission>
				
			</tr>
		</c:forEach>
		</tbody>
	</table>
	<div class="pagination">${page}</div>
</body>
</html>
